<?php

class Score_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    /*
     * string $uid 用户UID
     * return array() 用户好友各种分值
     */

    function getScore($uid) {
        $this->db->from("wb_score");
        $this->db->where("uid", $uid);
        $this->db->order_by("influence", "DESC");
        $this->db->limit(30);
        $query = $this->db->get();
        $score = $query->result_array();
        $sql = "select * from wb_twoway_relationship where uid='" . $uid . "' and (";
        $tempfid = "";
        $fsum = count($score);
        for ($index = 0; $index < $fsum; $index++) {
            if ($index != ($fsum - 1)) {
                $tempfid.="fname='" . $score[$index]["fid"] . "' or ";
            } else {
                $tempfid.="fname='" . $score[$index]["fid"] . "')";
            }
        }
        $userinfo = $this->db->query($sql . $tempfid)->result_array();

        foreach ($score as $key => $value) {
            foreach ($userinfo as $k => $user) {
                if ($value['fid'] === $user['fname']) {
                    if ($user['relation'] == "1") {
                        unset($score[$key]);
                        break;
                    }
                }
            }
        }
        return $score;
    }

    function getLeaderrank($uid) {
        $this->db->from("wb_score");
        $this->db->select("fid");
        $this->db->where("uid", $uid);
        $this->db->order_by("influence", "DESC");
        $query = $this->db->get();
        return $query->result_array();
    }

}

?>